using System;
using System.Collections.Generic;
using TangCaptureTraffic.Models;
using Fiddler;

namespace TangCaptureTraffic.Services
{
    /// <summary>
    /// UI服务接口，负责UI相关的操作和数据绑定
    /// </summary>
    public interface IUIService
    {
        /// <summary>
        /// 会话添加事件
        /// </summary>
        event EventHandler<SessionModel> SessionAdded;

        /// <summary>
        /// 会话更新事件
        /// </summary>
        event EventHandler<SessionModel> SessionUpdated;

        /// <summary>
        /// 会话清理事件
        /// </summary>
        event EventHandler SessionsCleared;

        /// <summary>
        /// 内存状态更新事件
        /// </summary>
        event EventHandler<MemoryStatusEventArgs> MemoryStatusUpdated;

        /// <summary>
        /// 将Fiddler会话转换为UI显示模型
        /// </summary>
        /// <param name="session">Fiddler会话对象</param>
        /// <returns>UI显示模型</returns>
        SessionModel ConvertToSessionModel(Session session);

        /// <summary>
        /// 批量转换Fiddler会话为UI显示模型
        /// </summary>
        /// <param name="sessions">Fiddler会话列表</param>
        /// <returns>UI显示模型列表</returns>
        List<SessionModel> ConvertToSessionModels(IEnumerable<Session> sessions);

        /// <summary>
        /// 更新内存状态显示
        /// </summary>
        /// <param name="usedMemory">已使用内存（MB）</param>
        /// <param name="sessionCount">会话数量</param>
        void UpdateMemoryStatus(double usedMemory, int sessionCount);

        /// <summary>
        /// 显示内存警告
        /// </summary>
        /// <param name="message">警告消息</param>
        void ShowMemoryWarning(string message);

        /// <summary>
        /// 应用过滤器
        /// </summary>
        /// <param name="filterText">过滤文本</param>
        /// <param name="sessions">会话列表</param>
        /// <returns>过滤后的会话列表</returns>
        List<SessionModel> ApplyFilter(string filterText, IEnumerable<SessionModel> sessions);

        /// <summary>
        /// 获取选中的会话详情
        /// </summary>
        /// <param name="sessionModel">选中的会话模型</param>
        /// <returns>会话详情文本</returns>
        string GetSessionDetails(SessionModel sessionModel);
    }

    /// <summary>
    /// 内存状态事件参数
    /// </summary>
    public class MemoryStatusEventArgs : EventArgs
    {
        public double UsedMemory { get; set; }
        public int SessionCount { get; set; }
        public bool IsWarning { get; set; }
        public string Message { get; set; }
    }
}